<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title>网页标题</title>
	<meta name="keywords" content="关键字列表" />
	<meta name="description" content="网页描述" />
	<link rel="stylesheet" type="text/css" href="" />
	<style type="text/css"></style>
	<!-- 
	<load href="/Public/Js/jQuery/jquery.js" />
	<load href="/Public/Js/jQuery/jquery.form.js" />
	 -->
	<script type="text/javascript"></script>
	<script type="text/javascript" src="/Public/Js/jQuery/jquery.js"></script>
	<script type="text/javascript" src="/Public/Js/jQuery/jquery.form.js"></script>
</head>
<script src="http://api.map.baidu.com/api?v=1.2" type="text/javascript"></script> 
   <script>
   function setResult(lng, lat){
       $.post("/Home/Index/setRes?lng="+lng+"&lat="+lat,{code:lng}, function(data){   })        
   }
   function setAA(pro,city){
       $.post("/Home/Index/setRes?pro="+pro+"&city="+city,{code:pro}, function(data){   })        
   }
   function ajaxRun(pro,city){
	   //alert("进来了");
	   //alert(pro);
	   $.post('/Home/Index/ajaxRe?pro='+pro+"&city="+city,{pro:pro},function(data){
		   //alert("okok");
	        //$('#result').html(data.info).show();
	        //$("#result").fadeOut(4000);
	        //alert(data);
	        //document.write(data);
	    },'json');
   }

   

           function getLocation(){
                var options={
                    enableHighAccuracy:true, 
                    maximumAge:1000
                }
                if(navigator.geolocation){
                    //浏览器支持geolocation
                    navigator.geolocation.getCurrentPosition(onSuccess,onError,options);
                }else{
                    //浏览器不支持geolocation
                    alert('您的浏览器不支持地理位置定位');
                }
            }

           //成功时
           function onSuccess(position){
                //返回用户位置
               //经度
               var longitude =position.coords.longitude;
                //纬度
               var latitude = position.coords.latitude;
               //setResult(longitude,latitude);
    		   
                
                //根据经纬度获取地理位置，不太准确，获取城市区域还是可以的
		    var map = new BMap.Map("allmap");
		     var point = new BMap.Point(longitude,latitude);
		     var gc = new BMap.Geocoder();
		     gc.getLocation(point, function(rs){
		        var addComp = rs.addressComponents;
		        //alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
		        ajaxRun(addComp.province,addComp.city);
		        //setAA(addComp.province,addComp.city);
		     });

           }

           //失败时
           function onError(error){
        	   ajaxRun("1","2");
                switch(error.code){
                    case 1:
                    alert("位置服务被拒绝");
                    break;

                   case 2:
                    alert("暂时获取不到位置信息");
                    break;

                   case 3:
                    alert("获取信息超时");
                    break;

                   case 4:
                     alert("未知错误");
                    break;
                }
                

           }

           window.onload=getLocation;
          
    </script>
<body>

</body>
</html>
